﻿using System;
using System.IO;

namespace FolderRenamer
{
    class Program
    {
        static void Main(string[] args)
        {
#if DEBUG
            Environment.CurrentDirectory = @"C:\Users\YANG.LEI\Downloads\重命名_测试";
#endif
            Console.WriteLine($"当前路径：{Environment.CurrentDirectory}");

            string[] txtFiles = Directory.GetFiles(Environment.CurrentDirectory, "*.txt");
            if (txtFiles.Length == 0)
            {
                Console.WriteLine("请确保exe旁边有重命名信息txt文件！");
            }
            else
            {
                string txtFile = txtFiles[0];
                Console.WriteLine($"重命名信息文件：{txtFile}");

                foreach (string line in File.ReadAllLines(txtFile, System.Text.Encoding.UTF8))
                {
                    string[] parts = line.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                    if (parts.Length == 2)
                    {
                        string from = parts[0].Trim();
                        string to = parts[1].Trim();
                        Console.WriteLine($"{from}--->{to}");
                        try
                        {
                            Directory.Move(from, to);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }

                    }
                }
            }
            Console.WriteLine("重命名完成!");
            Console.ReadKey();
        }
    }
}
